//
//  MYGMessageApi.swift
//  MYDoctor
//
//  Created by 小火科技 on 2024/4/17.
//

import UIKit
import Moya


enum MYGMessageApi {
    case sysMessage
    case getMessageNum
    case getMessageList(types:String)//医生端消息列表 5 系统消息 11 分诊代办  1 好友申请 7 协会通知
    case mayKnow(page:Int)
    case delkMayKnow(id:String)
    case applyFriend(target_doctor_id:String)//医生用户扫描其他医生分享的添加还有二维码时，需求请求该接口进行真正的好友添加
    case addDoctorFriend(target_doctor_id:String)// 医生添加好友
    case DoctorApplicationInfo(doctor_phone:String,report_id:String,patient_phone:String)//医生申请详情
    case agreeFriend(from_user_id:Int,to_user_id:Int,type:Int,sys_message_id:String)//同意好友请求
    case docorToPatientInfo(doctor_phone:String,patient_phone:String,report_ids:String)//医生发起查看患者数据申请
    case searchDoctor(kwd:String,department:String,hospital:String,title:String,page:Int,pageSize:Int = 20)//搜索医生好友
    case redMessage(msg_id:Int)//消息已读
    case doctorCofirm(params: [String: Any])//医生信息确认（是否接收患者）
    case getSysMessageList(patient_id:String)//消息模块 系统消息列表
}

extension MYGMessageApi: MYGTargetType {
    
    var params: [String : Any] {
        var params: [String: Any] = [:]
        switch self {
        case .sysMessage:
            break
        case .getMessageNum:
            break
        case let .getMessageList(types):
            params["types"] = types
        case let .delkMayKnow(id):
            params["id"] = id
        case let .applyFriend(target_doctor_id):
            params["target_doctor_id"] = target_doctor_id
        case let .addDoctorFriend(target_doctor_id):
            params["target_doctor_id"] = target_doctor_id
        case let .DoctorApplicationInfo(doctor_phone, report_id, patient_phone):
            params["doctor_phone"] = doctor_phone
            params["report_id"] = report_id
            params["patient_phone"] = patient_phone
        case let .agreeFriend(from_user_id, to_user_id, type,sys_message_id):
            params["from_user_id"] = from_user_id
            params["to_user_id"] = to_user_id
            params["type"] = type
            params["type"] = type
            params["sys_message_id"] = sys_message_id
        case let .docorToPatientInfo(doctor_phone, patient_phone, report_ids):
            params["doctor_phone"] = doctor_phone
            params["patient_phone"] = patient_phone
            params["report_ids"] = report_ids
        case let.searchDoctor(kwd, department, hospital, title, page, pageSize):
            params["kwd"] = kwd
            params["department"] = department
            params["hospital"] = hospital
            params["title"] = title
            params["pageSize"] = pageSize
            params["page"] = page
        case let .redMessage(msg_id):
            params["msg_id"] = msg_id
        case let .doctorCofirm(params):
            return params
        case let .getSysMessageList(patient_id):
            params["patient_id"] = patient_id
        case let .mayKnow(page):
            params["pageSize"] = 20
            params["page"] = page
        }
        return params
    }
    
    var path: String {
        switch self {
        case .sysMessage:
            "/api/micro/sys_messages"
        case .getMessageNum:
            "/api/micro/sys_messages/unread_num"
        case .getMessageList:
            "/api/micro/sys_messages/index_new"
        case .mayKnow:
            "/api/micro/may_know"
        case .delkMayKnow:
            "/api/micro/del_may_know"
        case.applyFriend:
            "/api/im/apply_friend"
        case.addDoctorFriend:
            "/api/im/apply_friend"
        case .DoctorApplicationInfo:
            "/api/doctor/DoctorApplicationInfo"
        case .agreeFriend:
            "/api/im/agree_friend"
        case .docorToPatientInfo:
            "/api/doctor/DoctorToPatientInfo"
        case .searchDoctor:
            "/api/doctor/search"
        case .redMessage:
            "/api/micro/sys_messages/read"
        case .doctorCofirm:
            "/api/referral/doctor/confirm"
        case .getSysMessageList:
            "/api/referral/notice"
        }
    }
    
    var baseURL: URL {
        switch self {
        case .getMessageNum,.sysMessage,.getMessageList,.mayKnow,.applyFriend,.addDoctorFriend,.delkMayKnow,.DoctorApplicationInfo,.agreeFriend,.docorToPatientInfo,.searchDoctor,.redMessage,.doctorCofirm,.getSysMessageList:
            return  URL(string: BaseUrl)!
//        case .delkMayKnow:
//            return  URL(string: "http://47.93.150.30:8083")!
        }
    }
    var method: Moya.Method {
        switch self {
        case .sysMessage,.mayKnow,.addDoctorFriend,.DoctorApplicationInfo,.docorToPatientInfo,.searchDoctor,.doctorCofirm,.getSysMessageList:
            .get
        case .getMessageNum:
            .get
        case .getMessageList,.delkMayKnow,.applyFriend,.agreeFriend,.redMessage:
                .post
        }
    }
    
    
    
    
}
